// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/catalog/namespace_manager.h>

namespace cantor::catalog {
    class NamespaceQuerier {
    public:
        NamespaceQuerier(NamespaceManager *namespace_manager) : namespace_manager_(namespace_manager) {
        }

        virtual ~NamespaceQuerier() = default;

        virtual int64_t max_id() const {
            std::shared_lock lk(namespace_manager_->_mutex);
            return namespace_manager_->_max_namespace_id;
        }

        virtual turbo::Result<int64_t> namespace_id(const std::string &name) const;

        virtual turbo::Result<std::shared_ptr<NamespaceInfo> > namespace_info(const std::string &name) const;

        virtual turbo::Result<std::shared_ptr<NamespaceInfo> > namespace_info(int64_t ns_id) const;

        virtual turbo::Result<turbo::flat_hash_set<int64_t> > databases(const std::string &name) const;

        virtual turbo::Result<turbo::flat_hash_set<int64_t> > databases(int64_t ns_id) const;

    private:
        NamespaceManager *namespace_manager_;
    };
} // namespace cantor::catalog
